#
# CMakeLists.txt
#
#  Created on: 12.04.2014
#      Author: Ralph Schurade
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# General CMake Setup
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

CMAKE_MINIMUM_REQUIRED( VERSION 2.8.8 )
PROJECT( gnomes )

# where to find our utils and cmake modules?
SET( TOOLS_DIR ${PROJECT_SOURCE_DIR}/../tools )

# append search path for FindModules:
LIST( APPEND CMAKE_MODULE_PATH ${TOOLS_DIR}/cmake )

INCLUDE( Utils )

OPTION( VERBOSE_MAKEFILE "More output on compilation" OFF )
IF ( VERBOSE_MAKEFILE MATCHES ON )
    set ( CMAKE_VERBOSE_MAKEFILE ON )
ENDIF()

IF ( NOT CMAKE_BUILD_TYPE )
    message( STATUS "No build type selected, default to Release" )
    set( CMAKE_BUILD_TYPE "Release" )
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Some common setup
# ---------------------------------------------------------------------------------------------------------------------------------------------------
SET( BinName "gnomes" )

# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
# CMake version 2.8.11.2 warns when the policy is not set
# and uses OLD behavior.
if(POLICY CMP0020)
  cmake_policy(SET CMP0020 NEW)
endif()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
# CXX flags
# ---------------------------------------------------------------------------------------------------------------------------------------------------
set( CMAKE_CXX_FLAGS "-Wall -pedantic -ansi -std=c++0x" )

# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Add sources as target
# ---------------------------------------------------------------------------------------------------------------------------------------------------
IF( CMAKE_HOST_SYSTEM MATCHES "Windows" )
    ADD_DEFINITIONS( -D__WINDOWS__ )
    
    IF ( CMAKE_BUILD_TYPE MATCHES "Release" )
        SET( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -mwindows" )
    ELSE() 
        SET( CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} " )
    ENDIF()
    
    # Collect the compile-files for this target
    COLLECT_COMPILE_FILES( "${CMAKE_CURRENT_SOURCE_DIR}" TARGET_CPP_FILES TARGET_H_FILES TARGET_TEST_FILES )
    
    # Tell CMake to run moc when necessary:
    SET ( CMAKE_AUTOMOC ON )
    # As moc files are generated in the binary dir, tell CMake
    # to always look for includes there:
    SET( CMAKE_INCLUDE_CURRENT_DIR ON )
    
    # Widgets finds its own dependencies.
    FIND_PACKAGE( Qt5Widgets REQUIRED )
    
    ADD_EXECUTABLE( ${BinName} ${TARGET_CPP_FILES} ${TARGET_H_FILES} ${QtIcon_RCC_SRCS})
    
    QT5_USE_MODULES( ${BinName} Widgets )
ENDIF()
